import store from '@/store'
import {
  get,
  post,
  put,
  del,
  postFile
} from '@/utils/request'
import {cityjosn} from "@/utils/city";
export const uploadFile = (data) => postFile('/farm-jdcx/config/yun', data)
export const getRegions = () => new Promise(resolve => {
    resolve({
        data: {
            children: cityjosn
        }
    })
})
export const getUserInfo = () => get('/farm-jdcx/system/user/profile')

// 部门
export const http_dept = {
  list: (params) => get('/farm-jdcx/system/dept/list', params),
  create: (data) => post('/farm-jdcx/system/dept', { }, data),
  update: (data) => put('/farm-jdcx/system/dept', { }, data),
  deleteOne: (id) => del(`/farm-jdcx/system/dept/${id}`)
}
// 人员
export const http_user = {
  list: (params) => get('/farm-jdcx/system/user/list', params),
  readChildren: (userId) => get(`/farm-jdcx/system/user/getChildren/${userId}`),
  create: (data) => post('/farm-jdcx/system/user', { }, data),
  update: (data) => put('/farm-jdcx/system/user', { }, data),
  deleteOne: (userId) => del('/farm-jdcx/system/user', { }, { userId }),
  updateStatus: (data) => put('/farm-jdcx/system/user/changeStatus', { }, data),
  downloadtemplate: () => post('/farm-jdcx/system/user/importTemplate', { }),
  upload: () => post('/farm-jdcx/system/user/importData', { }),
  userName: () => get('/farm-jdcx/system/user/nameList')
}
// 角色
export const http_role = {
  list: (params) => get('/farm-jdcx/system/role/list', params)
}

// 日志
export const http_log = {
  page: (params) => get('/farm-jdcx/monitor/operlog/list', params),
  export: (params) => post('/farm-jdcx/monitor/operlog/export', params),
  titleList: () => get('/farm-jdcx/monitor/operlog/list/title')
}
// 品牌申请
export const http_brand_apply = {
  page: (params) => get('/farm-jdcx/server/brandApply/list', params),
  detail: (id) => get(`/farm-jdcx/server/brandApply/${id}`)
}
// 品牌
export const http_brand = {
  page: (params) => get('/farm-jdcx/server/brandInfo/list', params),
  read: (id) => get(`/farm-jdcx/server/brandInfo/${id}`),
  create: (data) => post('/farm-jdcx/server/brandInfo', { }, data),
  update: (data) => put('/farm-jdcx/server/brandInfo', { }, data),
  deleteOne: (ids) => del(`/farm-jdcx/server/brandInfo/${ids}`)
}

// 品牌投诉
export const http_brand_audit = {
  page: (params) => get('/farm-jdcx/server/report/list', params),
  read: (id) => get(`/farm-jdcx/server/report/${id}`),
  updateStatus: (data) => put('/farm-jdcx/server/report', { }, data)
}

// 农作物
export const http_crop = {
  page: (params) => get('/farm-jdcx/crop/getCropList', params),
  create: (data) => post('/farm-jdcx/crop/addCrop', { }, data),
  update: (data) => post('/farm-jdcx/crop/updateCropType', { }, data),
  update2: (data) => post('/farm-jdcx/crop/updateCrop', { }, data),
  delete: (cropSubId) => post('/farm-jdcx/crop/delCropSubInfo', { cropSubId })
}
// 农作物信息
export const http_crop_info = {
  page: (params) => post('/farm-jdcx/crop/forCrops', params)
}

// 生育期维护
export const http_growthPeriod = {
  page: (params) => get('/farm-jdcx/server/pestControlGrowthPeriod/list', params),
  read: (id) => get(`/farm-jdcx/server/pestControlGrowthPeriod/${id}`),
  create: (data) => post('/farm-jdcx/server/pestControlGrowthPeriod/batchSava', { }, data),
  deleteOne: (id) => del(`/farm-jdcx/server/pestControlGrowthPeriod/${id}`)
}

// 病虫害维护
export const http_pest = {
  page: (params) => get('/farm-jdcx/server/pestControlInfo/list', params),
  read: (id) => get(`/farm-jdcx/server/pestControlInfo/${id}`),
  create: (data) => post('/farm-jdcx/server/pestControlInfo', { }, data),
  update: (data) => put('/farm-jdcx/server/pestControlInfo', { }, data),
  deleteOne: (id) => del(`/farm-jdcx/server/pestControlInfo/${id}`),
  updateStatus: (data) => put('/farm-jdcx/server/pestControlInfo/status', { }, data),
  cropList: () => get('/farm-jdcx/crop/getCropList')
}

// 土壤
export const http_land = {
  page: (params) => get('/farm-jdcx/fertilize-point/page', params),
  read: (id) => get(`/farm-jdcx/fertilize-point/detail`, { id }),
  create: (data) => post('/farm-jdcx/fertilize-point/upsert', { }, data),
  deleteOne: (data) => post(`/farm-jdcx/fertilize-point/del`, {}, data)
}
// 施肥方案
export const http_fertilize_plan = {
  page: (params) => get('/farm-jdcx/fertilize-plan/page', params),
  read: (id) => get(`/farm-jdcx/fertilize-plan/detail`, { id }),
  create: (data) => post('/farm-jdcx/fertilize-plan/upsert', { }, data),
  deleteOne: (data) => post(`/farm-jdcx/fertilize-plan/del`, {}, data)
}

// 工序组
export const http_process_group = {
  page: (params) => get('/farm-jdcx/plantProcess/queryProcessInfoTeamList', params),
  create: (data) => post('/farm-jdcx/plantProcess/modProcessInfoTeam', { }, data),
  update: (data) => post('/farm-jdcx/plantProcess/modProcessInfoTeam', { }, data),
  deleteOne: (id) => del(`/farm-jdcx/plantProcess/delProcessInfoTeam`, { id })
}

// 工序
export const http_process = {
  page: (params) => get('/farm-jdcx/plantProcess/queryProcessInfoList', params),
  read: (id) => get(`/farm-jdcx/server/pestControlInfo/${id}`),
  create: (data) => post('/farm-jdcx/plantProcess/insertProcessInfo', { }, data),
  deleteOne: (id) => post(`/farm-jdcx/plantProcess/delProcessInfo`, { id })
}

// 种植方案组
export const http_plant_group = {
  page: (params) => get('/farm-jdcx/plantPlan/queryPlantProcessTeamList', params),
  create: (data) => post('/farm-jdcx/plantPlan/modPlantProcessTeam', { }, data),
  update: (data) => post('/farm-jdcx/plantPlan/modPlantProcessTeam', { }, data),
  deleteOne: (id) => del(`/farm-jdcx/plantPlan/delPlantProcessTeam`, { id })
}

// 种植方案组-工序
export const http_plant_process = {
  page: (params) => get('/farm-jdcx/plantPlan/queryPlantProcessList', params),
  create: (data) => post('/farm-jdcx/plantPlan/modPlantProcessTeam', { }, data),
  update: (data) => post('/farm-jdcx/plantPlan/modPlantProcessTeam', { }, data),
  deleteOne: (id) => del(`/farm-jdcx/plantPlan/delPlantProcessTeam`, { id })
}

/**
 * 田块管理
 */
// 田分组
export const http_farmland_group = {
  page: (params) => get('/farm-jdcx/fieldGroup/list', params),
  create: (data) => post('/farm-jdcx/fieldGroup', { }, data),
  read: (id) => get(`/farm-jdcx/fieldGroup/${id}`),
  totalArea: (id) => get(`/farm-jdcx/fieldGroup/pcFieldArea`, { id }),
  update: (data) => put('/farm-jdcx/fieldGroup', { }, data),
  deleteOne: (id) => del(`/farm-jdcx/fieldGroup/${id}`),
  fieldPage: (params) => get('/farm-jdcx/fieldGroup/field-list', params),
  myFieldPage: (params) => get('/farm-jdcx/userField/myFieldArea', params)
}
// 田
export const http_farmland = {
  page: (params) => get('/farm-jdcx/field/list', params),
  create: (data) => post('/farm-jdcx/field', { }, data),
  totalArea: () => get(`/farm-jdcx/field/sumArea`),
  read: (id) => get(`/farm-jdcx/field/${id}`),
  weather: (xAxis, yAxis) => get(`/farm-jdcx/field/getWeather`, { xAxis, yAxis }),
  update: (data) => put('/farm-jdcx/field', { }, data),
  deleteOne: (id) => del(`/farm-jdcx/field/${id}`),
  // 田详情里面获取田的相关种植计划
  plant_detail: (params) => get('/farm-jdcx/plantPlanOfMob/queryFieldMemoByField', params),
  // 田详情里面获取田的土壤肥力
  solid_detail: (params) => get('/farm-jdcx/plantPlan/queryFieldSoilInfo', params),
  // 田详情里面获取田的温度
  temp_detail: (data) => post('/farm-jdcx/plantPlan/querySolieSqTemp', {}, data),
  // 积温积雨量
  accumulate: (params) => get('/farm-jdcx/field/getAccWeather', params)
}
// 移动/pc查询作物物候期列表
export function pestControlGrowthPeriodList(params) {
  return get(
    `/farm-jdcx/server/pestControlGrowthPeriod/list`,
    params
  );
}

// 移动端查询病虫害列表
export function pestControlInfoMList(params) {
  return get(
    `/farm-jdcx/server/pestControlInfo/mList`,
    params
  );
}

// 作物施肥方案
export function cropPlan(params) {
  return get(
    `/farm-jdcx/fertilize-plan/cropPlan`,
    params
  );
}
